<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ page contentType="text/html; charset=UTF-8" import="demo.*"%> 
<%@ page import="java.sql.*"%> 

<HEAD><TITLE>Registration</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">

</HEAD>

<BODY leftMargin=0 topMargin=10>

<TABLE cellSpacing=0 cellPadding=0 width=700 align=center border=0>
  <TBODY>
  <TR>
    <TD>
      <DIV align=center><A href="index.jsp"><IMG height=118 
      src="Pics/restaurantLogo.JPG" width=242 
  border=0></A></DIV></TD></TR></TBODY></TABLE>

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<tr><td><table width = 60% align = center>
<%
		DBConnector db = DBConnector.getDBConnector();
    	String RestID = "1";
    	String queryRestaurantName = "select rest_name from restaurant where rest_ID = " + RestID;
    	db.prepareStatement(queryRestaurantName);
    	ResultSet queryRestaurantNameResult = db.queryPstmt();
    	
    	if (queryRestaurantNameResult != null && queryRestaurantNameResult.next())
    		out.println("<tr><td align = center>" + queryRestaurantNameResult.getString(1) + "</td></tr>");
 %>
</table></td></tr>
<TR>
    <TD vAlign=top height=60>
    <TABLE cellSpacing=1 cellPadding=3 width="60%" align=center bgColor=#cccccc>
    <tr bgColor=#bbbbbb><td align = center colspan = 5>Profit</td></tr>
    <%   	
    	//DBConnector db = DBConnector.getDBConnector();
    	//String RestID = "1";
    	String queryRestaurantProfitCost = "select rest_revenue, rest_cost from restaurant where rest_ID = " + RestID;
    	db.prepareStatement(queryRestaurantProfitCost);
    	ResultSet queryRestaurantProfitCostResult = db.queryPstmt();
    	
    	if (queryRestaurantProfitCostResult != null && queryRestaurantProfitCostResult.next())
    	{
			Float Profit = queryRestaurantProfitCostResult.getFloat(1) - queryRestaurantProfitCostResult.getFloat(2);
    		out.println("<tr><td>Revenue : </td><td>" + queryRestaurantProfitCostResult.getString(1) + "</td></tr>");
    		out.println("<tr><td>Cost : </td><td>" + queryRestaurantProfitCostResult.getString(2) + "</td></tr>");
    		out.println("<tr><td>Profit : </td><td>" + Float.toString(Profit) + "</td></tr>");
    	}
     %>
    <tr><td></td></tr>
    </TABLE>
    </TD>
      </TR>
      
      <tr><td>
      <form action = "restaurant_account.jsp">
      <TABLE cellSpacing=1 cellPadding=3 width="60%" align=center bgColor=#cccccc>
      <tr bgColor=#bbbbbb><td align = center colspan = 5>The Food Sale</td></tr>
      <tr><td>Keyword : <input name="food_search" type="text" class="input" size="20"></td>
      <td>Order By</td>
      <td><input name = 'Order_By_Price' type = 'radio' class = 'input' value ='Order_By_Price'>Price</td>
      <td><input name = 'Order_By_Sales' type = 'radio' class = 'input' value ='Order_By_Sales'>Sales</td>
      <td><input name = 'Order_By_FoodName' type = 'radio' class = 'input' value ='Order_By_FoodName'>Food Name</td>
      </tr>
      <tr><td><INPUT type=submit value=search name=SubmitFoodSearch></td></tr>  
      </TABLE></form>
      <TABLE cellSpacing=1 cellPadding=3 width="60%" align=center bgColor=#eeeeee>
      <%
      	//DBConnector db = DBConnector.getDBConnector();	
		String SubmitFoodSearch = request.getParameter("SubmitFoodSearch");
		if (SubmitFoodSearch != null && SubmitFoodSearch.length() > 0) {
			String food_search = request.getParameter("food_search");
			String Order_By_FoodName = request
					.getParameter("Order_By_FoodName");
			String Order_By_Restaurant = request
					.getParameter("Order_By_Restaurant");
			String Order_By_Price = request.getParameter("Order_By_Price");
			String Order_By_Sales = request.getParameter("Order_By_Sales");
			String queryFoods = "select food_name, food_price, food_quantity from food, restaurant where food.rest_ID = restaurant.rest_ID and restaurant.rest_ID = " + RestID + " ";

			if (food_search != null && food_search.length() > 0)
				queryFoods += "and  (food_name like '%" + food_search
						+ "%' or rest_name like '%" + food_search
						+ "%' or food_price like '%" + food_search + "%') ";
			if (Order_By_Restaurant != null && Order_By_Restaurant.length() > 0)
				queryFoods += "order by restaurant.rest_name ";
			else if (Order_By_Price != null && Order_By_Price.length() > 0)
				queryFoods += "order by food_price ";
			else if (Order_By_Sales != null && Order_By_Sales.length() > 0)
				queryFoods += "order by food_quantity desc";
			else if (Order_By_FoodName != null && Order_By_FoodName.length() > 0)
				queryFoods += "order by food_name ";

			db.prepareStatement(queryFoods);
			ResultSet queryFoodResult = db.queryPstmt();
			if (queryFoodResult != null) {
				out.println("<tr bgColor=#cccccc><td>Food Name</td><td>Food Price</td><td># Sale</td></tr>");
				if (queryFoodResult.next()) {
					do {
						out.println("<tr>");
						out.println("<td>" + queryFoodResult.getString(1)
								+ "</td>");
						out.println("<td>" + queryFoodResult.getString(2)
								+ "</td>");
						out.println("<td>" + queryFoodResult.getString(3)
								+ "</td>");						
						out.println("</tr>");
					} while (queryFoodResult.next());
				} else
					out.println("<tr><td colspan = 5>There are no food information fulfilling your requirement.</td></tr>");
			}
		}
      %>         
      </TABLE>       
      </td></tr>
      </TABLE>  
</BODY>
